package com.github.sevenmall.orderservice.controller;

import com.github.sevenmall.orderservice.pojo.ao.OrderAO;
import com.github.sevenmall.orderservice.pojo.do0.SevenOrder;
import com.github.sevenmall.orderservice.pojo.vo.OrderVO;
import com.github.sevenmall.orderservice.service.OrderService;
import org.dozer.Mapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

/**
 * @author 杜科
 * @description
 * @contact AllenDuke@163.com
 * @date 2020/8/20
 */
@RestController("/order")
public class OrderController {

    @Autowired
    Mapper dozerMapper;

    @Autowired
    OrderService orderService;

    @PostMapping("/save")
    void save(@RequestBody OrderAO orderAO){
        SevenOrder order=dozerMapper.map(orderAO,SevenOrder.class);
        orderService.save(order);
    }

    @GetMapping("/getOrderById")
    OrderVO getOrderById(Long id){
        SevenOrder order = orderService.getOrder(id);
        OrderVO orderVO=dozerMapper.map(order,OrderVO.class);
        return orderVO;
    }

    @DeleteMapping("/deleteOrderById")
    void deleteOrderById(Long id){
        orderService.delate(id);
    }

    @PutMapping("/updateOrder")
    void update(@RequestBody OrderAO orderAO){
        SevenOrder order=dozerMapper.map(orderAO,SevenOrder.class);
        orderService.update(order);
    }
}
